//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    internal class ErrorToken : FormulaToken
    {
        public override FormulaTokenId TokenId
        {
            get { return FormulaTokenId.Err; }
        }
        private ErrorType _errorCode;

        public ErrorToken(ErrorType errorCode)
        {
            this._errorCode = errorCode;
        }

        public ErrorToken()
        {
        }

        public override ushort GetLength(FormulaReadContextType formulaReadContextType)
        {
            return 1;
        }

        internal override void ReadContent(FormulaReadContext context)
        {
            _errorCode = (ErrorType) context.ReadByte();
        }
        public override void WriteContent(FormulaWriteContext context)
        {
            context.WriteByte((byte)_errorCode);
        }

        internal override Expression GetExpression(FormulaEvaluationContext context)
        {
            return new ErrorExpression(Errors.GetError(_errorCode));
        }
    }
}